﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL.BussinessClass;
using Model;
using Model.ExtClass;

namespace AlltrustDinner.Pages.Admin
{
    public partial class OrderManagement : PageBase
    {

        public OrderManagement()
        {

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                OrderBiz biz = new OrderBiz();
                List<ITEM> Itemlist = biz.LoadTodayOrderItemList();
                var OrderSummaryList = (from l in Itemlist
                                       group l by new { l.RESTURANT, l.DINNER } into g
                                       select new
                                       {
                                           RESTURANT = g.Key.RESTURANT,
                                           DINNER = g.Key.DINNER,
                                           COUNT = g.Count()

                                       }).ToList().OrderBy(h => h.RESTURANT);

                this.rpt_order_list.DataSource = Itemlist;
                this.rpt_order_list.DataBind();

                this.rpt_order_summary.DataSource = OrderSummaryList;
                this.rpt_order_summary.DataBind();
            }
        }

        protected void imgBtn_search_Click(object sender, ImageClickEventArgs e)
        {
            OrderBiz biz = new OrderBiz();
            DateTime orderdate;
            DateTime.TryParse(this.ipt_datetime.Value, out orderdate);
            List<ITEM> Itemlist = biz.LoadOrderItemList(orderdate);
            this.rpt_order_list.DataSource = Itemlist;
            this.rpt_order_list.DataBind();
        }
    }
}